home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Kool / Kool.jar / kool / KoolScreen.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-12-24  |  28.1 KB  |  515 lines

  1. package kool;
  2.  
  3. import com.siemens.mp.game.ExtendedImage;
  4. import com.siemens.mp.game.GraphicObjectManager;
  5. import gamelib.Font;
  6. import gamelib.GameAction;
  7. import java.util.Timer;
  8. import java.util.TimerTask;
  9. import javax.microedition.lcdui.Canvas;
  10. import javax.microedition.lcdui.Graphics;
  11. import javax.microedition.lcdui.Image;
  12.  
  13. class KoolScreen extends GameScreen {
  14.    private byte[] background = new byte[]{31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -8, 5, 87, 119, -1, -33, 127, -38, -117, -95, 87, -5, -24, 0, 42, -86, -6, -69, -6, -12, 23, 80, 2, -1, 112, 21, 5, 85, 87, -41, 95, -48, 62, -96, 21, 127, -8, 0, 8, -118, -86, -86, -85, -128, 93, 72, 3, -1, 80, 5, 5, 85, 85, 85, 87, 64, 42, -112, 5, 95, -88, 0, 0, 8, -126, -86, -82, 0, 4, 0, 15, -81, -48, 1, 85, 85, 85, 85, 93, 0, 0, 0, 31, -9, -24, 0, 0, 40, 34, -86, -84, 0, 0, 0, -97, -9, -48, 5, 85, 85, 84, 5, 90, 0, 0, 0, 15, -41, 104, 0, 0, 2, -128, 32, 52, 0, 0, 0, -113, -10, -16, 4, 85, 85, 85, 85, 88, 0, 0, 0, 71, -41, 120, 0, 0, 0, 0, 2, -76, 2, -120, 0, -93, -89, -16, 0, 16, 17, 21, 85, 104, 23, -60, 0, 80, 79, 120, 0, 2, 0, 0, 0, 48, 47, -30, 0, 44, 31, -8, 0, 32, 1, 85, 81, 40, 31, -27, 0, 23, -3, 120, 0, 0, -128, 40, 0, 80, 62, -94, 0, 11, -2, -8, 0, 0, 21, 85, 85, 64, 125, 37, 64, 1, 85, -8, 0, 16, 0, -70, 0, 80, 62, 38, 0, 0, -86, -8, 0, 2, 85, 69, 85, 64, 61, 79, 64, 17, 85, -8, 0, 0, 10, -58, -88, 72, 26, -114, 0, -128, 43, -8, 0, 0, 85, 69, 85, 100, 15, 29, 64, 5, 87, -8, 0, 0, 0, -70, -96, 32, 32, 58, 4, 0, 43, -8, 0, 17, 20, 85, 85, 100, 16, -11, 0, 85, 95, -8, 0, 0, 2, -86, 0, 16, 10, -86, 80, 2, -85, -16, 0, 0, 20, 0, 84, 21, 65, 80, 1, 85, 127, -16, 0, 0, 0, -118, 0, 16, 0, 1, 84, 10, -81, -16, 0, 0, 64, 0, 4, 73, 64, 0, -87, 85, -1, -32, 0, 0, 2, 16, -128, 12, 0, 5, 90, -86, -65, -64, 0, 0, 0, 0, 2, 77, 64, -86, -27, 87, -1, -64, 0, 0, 0, 0, 0, 10, 0, 21, -118, 42, -1, -128, 0, 0, 0, 0, 0, 5, 98, -86, 21, -105, -1, 0, 0, 0, 0, 0, 0, 2, -48, 4, 63, -33, -2, 0, 0, 0, 0, 0, 0, 1, -22, 42, 126, -65, -4, 0, 0, 0, 0, 0, 0, 0, 53, 85, 117, 127, -8, 0, 0, 0, 0, 0, 0, 0, 10, -81, -85, -1, -32, 0, 0, 0, 0, 0, 0, 0, 7, -1, -1, -1, -64, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -2, 0, 0, 0, -128, 0, 0, 0, 0, 0, 31, -1, -16, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 3, 0, 20, 72, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 1, 0, 8, 0, 0, 0, 1, 0, 6, 0, 21, 81, 16, 16, 0, 0, 0, 0, 2, -128, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 1, 0, 0, 0, 21, 85, 85, 68, 64, 0, -128, 0, 0, 0, 0, 0, 10, -96, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 21, 85, 85, 85, 68, 68, 16, -128, 0, 0, 0, 0, 14, -86, -86, -96, 2, 2, 4, 42, -96, 0, 0, 0, 23, -9, 85, 85, 85, 85, 81, 0, 1, 68, 16, 0, 31, -81, -21, -22, -86, -86, -86, -86, -88, 0, 0, 0, 31, -3, -1, -1, -35, -9, -41, 85, 85, 85, 85, 80, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -8};
  15.    private byte[] player_bin = new byte[]{12, 0, 13, -32, 10, -16, 26, 56, 26, 56, 25, -18, 27, 118, 62, -42, 55, -112, 56, 16, 56, 8, 103, -8, 110, -32, 110, 112, -64, -16, 0, 0, 24, 0, 25, -32, 26, -16, 26, 56, 26, 56, 25, -20, 27, 124, 62, -36, 55, -112, 56, 16, 56, 8, 55, -8, 54, -32, 46, 112, 46, -16, 0, 0, 48, 0, 49, -32, 50, -16, 50, 56, 26, 56, 25, -18, 27, 118, 30, -42, 23, -112, 24, 16, 24, 8, 31, -8, 30, 112, 30, 56, 6, 112, 0, 0, 24, 0, 25, -32, 26, -16, 26, 56, 26, 56, 25, -20, 27, 124, 62, -36, 55, -112, 56, 16, 56, 8, 55, -8, 54, 112, 46, -16, 46, 0, 0, 0, 12, 0, 13, -32, 10, -16, 26, 56, 26, 56, 25, -18, 27, 118, 62, -42, 55, -112, 56, 16, 56, 8, 103, -8, 110, -32, 110, -16, -34, -16, 0, 0, 0, 48, 7, -80, 15, 80, 28, 88, 28, 88, 119, -104, 110, -40, 107, 124, 9, -20, 8, 28, 16, 28, 31, -26, 7, 118, 14, 118, 15, 3, 0, 0, 0, 24, 7, -104, 15, 88, 28, 88, 28, 88, 55, -104, 62, -40, 59, 124, 9, -20, 8, 28, 16, 28, 31, -20, 7, 108, 14, 116, 15, 116, 0, 0, 0, 12, 7, -116, 15, 76, 28, 76, 28, 88, 119, -104, 110, -40, 107, 120, 9, -24, 8, 24, 16, 24, 31, -8, 14, 120, 28, 120, 14, 96, 0, 0, 0, 24, 7, -104, 15, 88, 28, 88, 28, 88, 55, -104, 62, -40, 59, 124, 9, -20, 8, 28, 16, 28, 31, -20, 14, 108, 15, 116, 0, 116, 0, 0, 0, 48, 7, -80, 15, 80, 28, 88, 28, 88, 119, -104, 110, -40, 107, 124, 9, -20, 8, 28, 16, 28, 31, -26, 7, 118, 15, 118, 15, 123, 0, 0};
  16.    private byte[] player_mask = new byte[]{12, 0, 13, -32, 11, -16, 27, -8, 27, -8, 25, -18, 27, -10, 63, -10, 55, -16, 63, -16, 63, -8, 103, -8, 110, -32, 110, 112, -64, -16, 0, 0, 24, 0, 25, -32, 27, -16, 27, -8, 27, -8, 25, -20, 27, -4, 63, -4, 55, -16, 63, -16, 63, -8, 55, -8, 54, -32, 46, 112, 46, -16, 0, 0, 48, 0, 49, -32, 51, -16, 51, -8, 27, -8, 25, -18, 27, -10, 31, -10, 23, -16, 31, -16, 31, -8, 31, -8, 30, 112, 30, 56, 6, 112, 0, 0, 24, 0, 25, -32, 27, -16, 27, -8, 27, -8, 25, -20, 27, -4, 63, -4, 55, -16, 63, -16, 63, -8, 55, -8, 54, 112, 46, -16, 46, 0, 0, 0, 12, 0, 13, -32, 11, -16, 27, -8, 27, -8, 25, -18, 27, -10, 63, -10, 55, -16, 63, -16, 63, -8, 103, -8, 110, -32, 110, -16, -34, -16, 0, 0, 0, 48, 7, -80, 15, -48, 31, -40, 31, -40, 119, -104, 111, -40, 111, -4, 15, -20, 15, -4, 31, -4, 31, -26, 7, 118, 14, 118, 15, 3, 0, 0, 0, 24, 7, -104, 15, -40, 31, -40, 31, -40, 55, -104, 63, -40, 63, -4, 15, -20, 15, -4, 31, -4, 31, -20, 7, 108, 14, 116, 15, 116, 0, 0, 0, 12, 7, -116, 15, -52, 31, -52, 31, -40, 119, -104, 111, -40, 111, -8, 15, -24, 15, -8, 31, -8, 31, -8, 14, 120, 28, 120, 14, 96, 0, 0, 0, 24, 7, -104, 15, -40, 31, -40, 31, -40, 55, -104, 63, -40, 63, -4, 15, -20, 15, -4, 31, -4, 31, -20, 14, 108, 15, 116, 0, 116, 0, 0, 0, 48, 7, -80, 15, -48, 31, -40, 31, -40, 119, -104, 111, -40, 111, -4, 15, -20, 15, -4, 31, -4, 31, -26, 7, 118, 15, 118, 15, 123, 0, 0};
  17.    private byte[] ball_L = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 72, 73, 68, 65, 84, 120, -38, 99, -8, -113, 10, 24, 48, 0, -70, 2, 76, -91, 88, -11, -93, 107, -64, 106, 24, 86, 61, 12, 120, 84, 99, 117, 30, 84, 3, 30, 69, -24, 26, -48, 89, -60, 0, 98, -52, -58, 97, 17, -83, 52, -48, 24, -112, -28, 30, -108, -120, 35, 65, 3, -111, 122, 112, 38, 62, 60, -86, 81, 52, 16, -103, -68, 1, -75, 41, -38, 38, 94, 19, -54, 110, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  18.    private byte[] mask_L = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 50, 73, 68, 65, 84, 120, -38, 99, -8, -113, 10, 24, 48, 0, -70, 2, 60, 74, -79, 106, 99, 32, 70, 53, -78, 30, 6, 34, 85, -61, -11, -112, -82, 97, 20, 80, 61, -92, -56, -115, 56, -110, -109, 6, 57, -119, -113, -8, -28, 13, 0, -77, 101, -113, 113, 107, 39, 112, -111, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  19.    private byte[] ball_M = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 55, 73, 68, 65, 84, 120, -38, 99, -8, 15, 3, 12, 72, -32, 63, 110, -64, -128, -84, 20, 77, 39, 62, 13, -60, -37, -125, -112, 99, -64, 6, -80, 107, -64, -91, 26, -89, 6, 60, -128, 26, 26, 72, 114, 15, -71, 26, 72, -114, 56, -110, -64, -120, -44, 0, 0, 107, -38, 34, -6, -100, 56, 80, -123, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  20.    private byte[] mask_M = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 39, 73, 68, 65, 84, 120, -38, 99, -8, 15, 3, 12, 72, -32, 63, 110, -64, -128, -90, -108, -96, 54, -46, 53, -32, 7, 67, 67, 3, -19, 67, -119, -100, -120, 35, 9, -116, 72, 13, 0, -45, 109, 14, 15, -124, 94, -109, 7, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  21.    private byte[] ball_S = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 8, 0, 0, 0, 8, 8, 2, 0, 0, 0, 75, 109, 41, -36, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 33, 73, 68, 65, 84, 120, -38, 99, -8, -1, -1, 63, 3, 12, -4, 71, 2, 80, 62, -90, 28, 3, 26, 32, 66, 2, -89, 29, -1, 113, 0, -46, 37, 0, -27, 35, -125, 125, -100, -101, 70, -20, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  22.    private byte[] mask_S = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 8, 0, 0, 0, 8, 8, 2, 0, 0, 0, 75, 109, 41, -36, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 30, 73, 68, 65, 84, 120, -38, 99, -8, -1, -1, 63, 3, 12, -4, 71, 2, 12, 104, -128, 18, 9, -100, 118, -4, -57, 1, 72, -105, 0, 0, -23, 3, -128, -128, -12, 47, -60, 31, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
  23.    private byte[] shot_bin = new byte[]{-76, -39, 77, -108, -39, 77, -108, -39, 77, -108, -39, 77, -108, -39, 77, -108, -39, 77};
  24.    public static final int GRAVITY = 320;
  25.    public static final int GAMESPEED = 100;
  26.    public static final int BALLTYPE = 0;
  27.    public static final int BALLNUM = 1;
  28.    public static final int BALLTYPENEW = 2;
  29.    public static final int BALLNEWDEF = 3;
  30.    public static final int BALLXSPEED = 0;
  31.    public static final int BALLYSPEED = 1;
  32.    public static final int BIGBALL = 14;
  33.    public static final int MEDIUMBALL = 10;
  34.    public static final int SMALLBALL = 6;
  35.    public static final int OBSTACLEH = 1;
  36.    public static final int OBSTACLEV = 2;
  37.    public static final int PAUSE_MODE = -1;
  38.    public static final int GAME_MODE = 1;
  39.    public static final int GAMEOVER_MODE = 2;
  40.    public static final int NEXTLEVEL_MODE = 3;
  41.    public static final int DIE_MODE = 4;
  42.    public static final int COLLISIONTOP = 16;
  43.    public static final int COLLISIONLEFT = 1;
  44.    public static final int COLLISIONRIGHT = 2;
  45.    public static final int COLLISIONBOTTOM = 32;
  46.    public static final int COLLISIONINSIDE = 1024;
  47.    private static final int PRESSED = 1;
  48.    private static final int RELEASED = 0;
  49.    private static final int REPEATED = 1;
  50.    private static final int GAME_SCREEN_WIDTH = 96;
  51.    private static final int GAME_SCREEN_HEIGHT = 56;
  52.    int[][] ballExplode = new int[][]{{14, 2, 10, 3, 100, -2, 100}, {10, 2, 6, 3, 80, -3, 80}};
  53.    int[][][] levelBalls = new int[][][]{new int[0][], {{14, 20, 0, 1}}, {{14, 10, 0, 1}, {10, 80, 0, 3}}, {{14, 40, 0, 1}}, {{10, 10, 0, 3}, {10, 80, 0, -3}}, {{14, 20, 0, 2}, {10, 70, 0, -3}}, {{10, 10, 0, 3}, {10, 40, 0, -3}, {10, 80, 0, 3}}, {{14, 10, 0, -1}, {14, 80, 0, 1}}, {{10, 10, 0, -3}, {10, 60, 0, 3}, {10, 75, 10, -2}}, {{14, 10, 0, 1}, {10, 35, 0, -3}, {10, 80, 0, 3}}};
  54.    int[][][] levelObstacles = new int[][][]{new int[0][], new int[0][], new int[0][], {{2, 45, 16}}, {{1, 25, 25}, {1, 35, 25}}, {{1, 17, 30}, {1, 27, 30}}, {{1, 15, 30}, {1, 70, 30}}, {{2, 45, 6}, {2, 40, 33}}, {{2, 45, 5}, {1, 65, 25}}, {{2, 40, 30}}};
  55.    private int currentKey;
  56.    private int currentKeyState = 0;
  57.    private int fieldX = 0;
  58.    private int fieldY = 0;
  59.    public boolean bRunning;
  60.    public boolean readyToPaint = false;
  61.    private Image gameScreenImage;
  62.    private ExtendedImage gameScreen = null;
  63.    private ExtendedImage statusScreen;
  64.    private GraphicObjectManager gfxManager;
  65.    public Player player;
  66.    private Ball[] balls;
  67.    private Shoot shoot;
  68.    private Timer timer = new Timer();
  69.    private TimerTask counterTask;
  70.    protected int seconds;
  71.    private int currentLevel = 1;
  72.    private int gameMode = -1;
  73.    private GameAction action;
  74.    private Obstacle[] obstacles = new Obstacle[10];
  75.  
  76.    public KoolScreen() {
  77.       try {
  78.          this.gfxManager = new GraphicObjectManager();
  79.          this.gameScreenImage = Image.createImage(96, 56);
  80.          this.gameScreen = new ExtendedImage(this.gameScreenImage);
  81.          this.gameScreen.clear((byte)0);
  82.          this.statusScreen = new ExtendedImage(Image.createImage(96, 10));
  83.          this.statusScreen.clear((byte)0);
  84.          Image ballS = Image.createImage(this.ball_S, 0, this.ball_S.length);
  85.          Image ballM = Image.createImage(this.ball_M, 0, this.ball_M.length);
  86.          Image ballL = Image.createImage(this.ball_L, 0, this.ball_L.length);
  87.          Image maskS = Image.createImage(this.mask_S, 0, this.mask_S.length);
  88.          Image maskM = Image.createImage(this.mask_M, 0, this.mask_M.length);
  89.          Image maskL = Image.createImage(this.mask_L, 0, this.mask_L.length);
  90.          this.shoot = new Shoot(1);
  91.          this.gfxManager.addObject(this.shoot);
  92.          this.player = new Player(this.player_bin, this.player_mask, 16, 16, 10);
  93.          this.player.setPosition(48, 41);
  94.          this.gfxManager.addObject(this.player);
  95.          this.balls = new Ball[24];
  96.  
  97.          for(int i = 0; i < 2; ++i) {
  98.             this.balls[i] = new Ball(0, 0, ballL, maskL, 14, 0, 0);
  99.             this.balls[i].setVisible(false);
  100.             this.balls[i].setCollisionRectangle(2, 2, 12, 12);
  101.             this.gfxManager.addObject(this.balls[i]);
  102.          }
  103.  
  104.          for(int i = 2; i < 8; ++i) {
  105.             this.balls[i] = new Ball(0, 0, ballM, maskM, 10, 0, 0);
  106.             this.balls[i].setVisible(false);
  107.             this.balls[i].setCollisionRectangle(2, 2, 8, 8);
  108.             this.gfxManager.addObject(this.balls[i]);
  109.          }
  110.  
  111.          for(int i = 8; i < 24; ++i) {
  112.             this.balls[i] = new Ball(0, 0, ballS, maskS, 6, 0, 0);
  113.             this.balls[i].setVisible(false);
  114.             this.balls[i].setCollisionRectangle(0, 0, 6, 6);
  115.             this.gfxManager.addObject(this.balls[i]);
  116.          }
  117.  
  118.          for(int i = 0; i < this.obstacles.length / 2; ++i) {
  119.             this.obstacles[i] = new Obstacle(2);
  120.             this.obstacles[i].setVisible(false);
  121.             this.gfxManager.addObject(this.obstacles[i]);
  122.             this.obstacles[i + this.obstacles.length / 2] = new Obstacle(1);
  123.             this.obstacles[i + this.obstacles.length / 2].setVisible(false);
  124.             this.gfxManager.addObject(this.obstacles[i + this.obstacles.length / 2]);
  125.          }
  126.       } catch (Exception e) {
  127.          ((Throwable)e).printStackTrace();
  128.       }
  129.  
  130.       System.gc();
  131.       this.readyToPaint = true;
  132.       this.startLevel();
  133.    }
  134.  
  135.    private void startLevel() {
  136.       this.player.setPosition(48, 41);
  137.  
  138.       for(int i = 0; i < this.levelBalls[this.currentLevel].length; ++i) {
  139.          int ball = this.findFreeBall(this.levelBalls[this.currentLevel][i][0]);
  140.          if (ball >= 0) {
  141.             this.balls[ball].setPosition(this.levelBalls[this.currentLevel][i][1] + this.fieldX, this.levelBalls[this.currentLevel][i][2] + this.fieldY);
  142.             this.balls[ball].ySpeed = 200;
  143.             this.balls[ball].xSpeed = this.levelBalls[this.currentLevel][i][3];
  144.             this.balls[ball].setVisible(true);
  145.          }
  146.       }
  147.  
  148.       for(int i = 0; i < this.levelObstacles[this.currentLevel].length; ++i) {
  149.          int o = this.findFreeObstacle(this.levelObstacles[this.currentLevel][i][0]);
  150.          if (o >= 0) {
  151.             this.obstacles[o].setPosition(this.levelObstacles[this.currentLevel][i][1] + this.fieldX, this.levelObstacles[this.currentLevel][i][2] + this.fieldY);
  152.             this.obstacles[o].setVisible(true);
  153.          }
  154.       }
  155.  
  156.       this.seconds = 90;
  157.       this.timer.scheduleAtFixedRate(this.counterTask = new 1(this), 1000L, 1000L);
  158.       this.gameMode = 1;
  159.    }
  160.  
  161.    private void finishLevel() {
  162.       for(int i = 0; i < this.balls.length; ++i) {
  163.          this.balls[i].setVisible(false);
  164.       }
  165.  
  166.       for(int i = 0; i < this.obstacles.length; ++i) {
  167.          this.obstacles[i].setVisible(false);
  168.       }
  169.  
  170.       this.counterTask.cancel();
  171.       this.shoot.setVisible(false);
  172.    }
  173.  
  174.    public void Dispose() {
  175.       this.gameScreen = null;
  176.       this.gfxManager = null;
  177.    }
  178.  
  179.    protected void keyPressed(int keyCode) {
  180.       int action = ((Canvas)this).getGameAction(keyCode);
  181.       if (keyCode != 53 && action != 8) {
  182.          if (keyCode != 52 && action != 2) {
  183.             if (keyCode == 54 || action == 5) {
  184.                this.currentKey = 5;
  185.                this.currentKeyState = 1;
  186.             }
  187.          } else {
  188.             this.currentKey = 2;
  189.             this.currentKeyState = 1;
  190.          }
  191.       } else {
  192.          this.addShot();
  193.       }
  194.  
  195.    }
  196.  
  197.    protected void keyReleased(int keyCode) {
  198.       int action = ((Canvas)this).getGameAction(keyCode);
  199.       if (keyCode != 52 && action != 2) {
  200.          if (keyCode == 54 || action == 5) {
  201.             this.currentKey = 5;
  202.             this.currentKeyState = 0;
  203.          }
  204.       } else {
  205.          this.currentKey = 2;
  206.          this.currentKeyState = 0;
  207.       }
  208.  
  209.       if (keyCode == 48) {
  210.          this.finishLevel();
  211.          ++this.currentLevel;
  212.          this.startLevel();
  213.       }
  214.  
  215.    }
  216.  
  217.    protected void keyRepeated(int keyCode) {
  218.    }
  219.  
  220.    private void addShot() {
  221.       if (!this.shoot.getVisible()) {
  222.          this.shoot.fire(this.player);
  223.       }
  224.  
  225.    }
  226.  
  227.    private void ballExplode(int ball) {
  228.       int n = -1;
  229.       if (this.balls[ball].size == 14) {
  230.          n = 0;
  231.       } else if (this.balls[ball].size == 10) {
  232.          n = 1;
  233.       }
  234.  
  235.       Player var10000 = this.player;
  236.       var10000.score += (n + 1) * 3;
  237.       this.balls[ball].setVisible(false);
  238.       if (n >= 0) {
  239.          for(int i = 0; i < this.ballExplode[n][1]; ++i) {
  240.             int fball = this.findFreeBall(this.ballExplode[n][2]);
  241.             if (fball >= 0) {
  242.                this.balls[fball].setPosition(this.balls[ball].getXPosition() - (this.ballExplode[n][3 + i * 2] < 0 ? 7 : -7), this.balls[ball].getYPosition());
  243.                this.balls[fball].xSpeed = this.ballExplode[n][3 + i * 2 + 0];
  244.                this.balls[fball].ySpeed = this.balls[ball].ySpeed * this.ballExplode[n][3 + i * 2 + 1] / 100;
  245.                this.balls[fball].setVisible(true);
  246.             }
  247.          }
  248.       }
  249.  
  250.    }
  251.  
  252.    private final int findFreeBall(int type) {
  253.       for(int i = 0; i < this.balls.length; ++i) {
  254.          if (!this.balls[i].getVisible() && this.balls[i].size == type) {
  255.             return i;
  256.          }
  257.       }
  258.  
  259.       return -1;
  260.    }
  261.  
  262.    private final int findFreeObstacle(int type) {
  263.       for(int i = 0; i < this.obstacles.length; ++i) {
  264.          if (this.obstacles[i].type == type && !this.obstacles[i].getVisible()) {
  265.             return i;
  266.          }
  267.       }
  268.  
  269.       return -1;
  270.    }
  271.  
  272.    public void movePlayer() {
  273.       int dx = 0;
  274.       if (this.currentKeyState == 1 && this.currentKey == 2) {
  275.          dx = -this.player.speed;
  276.       } else if (this.currentKeyState == 1 && this.currentKey == 5) {
  277.          dx = this.player.speed;
  278.       }
  279.  
  280.       if (this.player.getXPosition() + dx - 1 < 81 && this.player.getXPosition() + dx >= this.fieldX) {
  281.          this.player.setPosition(this.player.getXPosition() + dx, this.player.getYPosition());
  282.          if (dx < 0 && this.player.orientation != 0) {
  283.             this.player.setOrientation(0);
  284.          }
  285.  
  286.          if (dx > 0 && this.player.orientation != 5) {
  287.             this.player.setOrientation(5);
  288.          }
  289.  
  290.          if (dx != 0) {
  291.             this.player.animate();
  292.          }
  293.  
  294.       }
  295.    }
  296.  
  297.    public synchronized void moveObjects() {
  298.       int width = 96;
  299.       int height = 56;
  300.       if (this.shoot.getVisible()) {
  301.          this.shoot.move();
  302.       }
  303.  
  304.       int xc = 0;
  305.       int yc = 0;
  306.       if (this.shoot.getVisible()) {
  307.          for(int i = 0; i < this.balls.length; ++i) {
  308.             if (this.balls[i].getVisible() && this.shoot.isCollidingWith(this.balls[i])) {
  309.                this.ballExplode(i);
  310.             }
  311.          }
  312.       }
  313.  
  314.       int ballCount = 0;
  315.  
  316.       for(int i = 0; i < this.balls.length; ++i) {
  317.          if (this.balls[i].getVisible()) {
  318.             ++ballCount;
  319.  
  320.             for(int o = 0; o < this.obstacles.length; ++o) {
  321.                if (this.obstacles[o].getVisible()) {
  322.                   int[] obs = this.obstacles[o].getCollisionRectangle();
  323.                   int c = this.ballCollision(this.balls[i].getXPosition(), this.balls[i].getYPosition(), this.balls[i].size, obs);
  324.                   if ((c & 16) != 0) {
  325.                      if (this.balls[i].ySpeed > 0) {
  326.                         Ball var10000 = this.balls[i];
  327.                         var10000.ySpeed *= -1;
  328.                      }
  329.                   } else if ((c & 32) != 0 && this.balls[i].ySpeed < 0) {
  330.                      Ball var11 = this.balls[i];
  331.                      var11.ySpeed *= -1;
  332.                   }
  333.  
  334.                   if ((c & 1) != 0) {
  335.                      if (this.balls[i].xSpeed > 0) {
  336.                         Ball var12 = this.balls[i];
  337.                         var12.xSpeed *= -1;
  338.                      }
  339.                   } else if ((c & 2) != 0 && this.balls[i].xSpeed < 0) {
  340.                      Ball var13 = this.balls[i];
  341.                      var13.xSpeed *= -1;
  342.                   }
  343.                }
  344.             }
  345.  
  346.             if (this.balls[i].getXPosition() + this.balls[i].xSpeed >= width - this.balls[i].size + this.fieldX) {
  347.                this.balls[i].setPosition(width - this.balls[i].size + this.fieldX, this.balls[i].getYPosition());
  348.                this.balls[i].xSpeed = -this.balls[i].xSpeed;
  349.             } else if (this.balls[i].getXPosition() + this.balls[i].xSpeed <= this.fieldX) {
  350.                this.balls[i].setPosition(this.fieldX, this.balls[i].getYPosition());
  351.                this.balls[i].xSpeed = -this.balls[i].xSpeed;
  352.             } else {
  353.                this.balls[i].setPosition(this.balls[i].getXPosition() + this.balls[i].xSpeed, this.balls[i].getYPosition());
  354.             }
  355.  
  356.             this.balls[i].ySpeed += 320;
  357.             this.balls[i].setPosition(this.balls[i].getXPosition(), this.balls[i].getYPosition() + this.balls[i].ySpeed / 1000);
  358.             if (this.balls[i].getYPosition() >= height + this.fieldY - this.balls[i].size) {
  359.                this.balls[i].setPosition(this.balls[i].getXPosition(), height + this.fieldY - this.balls[i].size);
  360.                this.balls[i].ySpeed = -this.balls[i].ySpeed;
  361.             }
  362.  
  363.             if (this.balls[i].isCollidingWith(this.player)) {
  364.                this.action = new 2(this);
  365.                return;
  366.             }
  367.          }
  368.       }
  369.  
  370.       if (ballCount == 0) {
  371.          this.gameMode = 3;
  372.       }
  373.  
  374.    }
  375.  
  376.    private final int ballCollision(int bx, int by, int r, int[] shape) {
  377.       bx += r / 2;
  378.       by += r / 2;
  379.       int where = 0;
  380.       int testX = bx;
  381.       int testY = by;
  382.       int br = r / 2 * (r / 2);
  383.       if (bx < shape[0]) {
  384.          testX = shape[0];
  385.          where |= 1;
  386.       } else if (bx > shape[0] + shape[2]) {
  387.          testX = shape[0] + shape[2];
  388.          where |= 2;
  389.       }
  390.  
  391.       if (by < shape[1]) {
  392.          testY = shape[1];
  393.          where |= 16;
  394.       } else if (by > shape[1] + shape[3]) {
  395.          testY = shape[1] + shape[3];
  396.          where |= 32;
  397.       }
  398.  
  399.       return this.dist(bx, by, testX, testY) <= br ? where : 0;
  400.    }
  401.  
  402.    private final int dist(int x1, int y1, int x2, int y2) {
  403.       return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  404.    }
  405.  
  406.    public void paint(Graphics g) {
  407.       if (this.gameScreen != null && this.readyToPaint) {
  408.          this.gameScreen.blitToScreen(0, 13);
  409.       }
  410.  
  411.    }
  412.  
  413.    public int getReturnValue() {
  414.       return 0;
  415.    }
  416.  
  417.    public void run() {
  418.       this.bRunning = true;
  419.  
  420.       while(this.bRunning) {
  421.          try {
  422.             Graphics g = this.gameScreen.getImage().getGraphics();
  423.             g.setClip(0, 0, 96, 56);
  424.             switch (this.gameMode) {
  425.                case 2:
  426.                   Thread.yield();
  427.                   g.setColor(16777215);
  428.                   g.fillRect(4, 4, 88, 48);
  429.                   g.setColor(0);
  430.                   g.drawRect(4, 4, 88, 48);
  431.                   g.drawString("Game Over!", 18, 15, 20);
  432.                   Font.drawString(g, "you scored: ".concat(String.valueOf(String.valueOf(this.player.score))), 13, 36);
  433.                   this.gameScreen.blitToScreen(0, 13);
  434.                   Thread.sleep(4000L);
  435.                   this.bRunning = false;
  436.                   break;
  437.                case 3:
  438.                   Thread.yield();
  439.                   this.finishLevel();
  440.                   g.setColor(16777215);
  441.                   g.fillRect(4, 4, 88, 48);
  442.                   g.setColor(0);
  443.                   g.drawRect(4, 4, 88, 48);
  444.                   g.drawString("Well done!", 20, 9, 20);
  445.                   Font.drawString(g, "level bonus:", 9, 28);
  446.                   Font.drawString(g, "time bonus:", 9, 36);
  447.                   int levelBonus = this.currentLevel * 20;
  448.                   int timeBonus = this.seconds;
  449.                   Font.drawString(g, Integer.toString(levelBonus), 57, 28);
  450.                   Font.drawString(g, Integer.toString(timeBonus), 57, 36);
  451.                   Player var7 = this.player;
  452.                   var7.score += levelBonus + timeBonus;
  453.                   this.gameScreen.blitToScreen(0, 13);
  454.                   var7 = this.player;
  455.                   var7.score += 250;
  456.                   ++this.currentLevel;
  457.                   Thread.sleep(3500L);
  458.                   this.startLevel();
  459.                   break;
  460.                case 4:
  461.                   Thread.yield();
  462.                   --this.player.lives;
  463.                   if (this.player.lives <= 0) {
  464.                      this.gameMode = 2;
  465.                   } else {
  466.                      g.setColor(16777215);
  467.                      g.fillRect(4, 4, 88, 48);
  468.                      g.setColor(0);
  469.                      g.drawRect(4, 4, 88, 48);
  470.                      g.drawString(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(this.player.lives)))).append(this.player.lives == 1 ? " life" : " lives").append(" left!"))), 18, 20, 20);
  471.                      this.gameScreen.blitToScreen(0, 13);
  472.                      Thread.sleep(2000L);
  473.                      this.finishLevel();
  474.                      this.startLevel();
  475.                   }
  476.             }
  477.  
  478.             Thread.yield();
  479.          } catch (Exception var5) {
  480.          }
  481.  
  482.          if (this.gameMode == 1) {
  483.             if (this.action != null) {
  484.                this.action.performAction();
  485.                if (this.action.isOver()) {
  486.                   this.action = null;
  487.                }
  488.             } else {
  489.                this.moveObjects();
  490.                this.movePlayer();
  491.             }
  492.          }
  493.  
  494.          try {
  495.             this.gameScreen.setPixels(this.background, 0, 0, 96, 56);
  496.             this.gfxManager.paint(this.gameScreen, 0, 0);
  497.             this.statusScreen.clear((byte)0);
  498.             this.statusScreen.getImage().getGraphics().drawString("Score:".concat(String.valueOf(String.valueOf(this.player.score))), 0, 0, 20);
  499.             String s = String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(this.seconds / 60)))).append(":").append(this.seconds % 60 < 10 ? "0" : "").append(this.seconds % 60)));
  500.             this.statusScreen.getImage().getGraphics().drawString(s, 71, 0, 20);
  501.             this.gameScreen.blitToScreen(0, 13);
  502.             this.statusScreen.blitToScreen(0, 0);
  503.          } catch (Exception e) {
  504.             ((Throwable)e).printStackTrace();
  505.          }
  506.       }
  507.  
  508.    }
  509.  
  510.    // $FF: synthetic method
  511.    static int access$0(KoolScreen x$0, int x$1) {
  512.       return x$0.gameMode = x$1;
  513.    }
  514. }
  515.